<?php
include("UserIncludes/DbConfig.php");
 $id=$_REQUEST['id'];

/*
---------Fetch and show add---------

For showing the add frist fetch data from adspace_details and advertise_master where adspaceIdMd=requested id.
then take the adspaceId from adspace_details and check from advertise_details table if the networkId is 0 or not.

1.If network id is 0 (means this is a direct add) then take the adspaceId.
then take the style, color, width, height, etc from adspace_details matching that adspaceId

use this as the style in the below table. and show all data from advertise_details , advertise_master where adspaceId is equal to requested id.

2. If network id is != 0 (means this is a network add) then take the networkId and find category id from network table.and find the highest bidder and using this category id find adsiteId from adsite_master and using this adsiteId from adspace_master find how meny space are involve with this adsiteId and and find clickPerDay. and 
finally show that highest bidder's advertise into the highest clikable publisher's site. 

*/



// This query is only for direct ADS but not for custom ads.......
	  $sql_advertise="select * from advertise_details AD, adspace_details SD,advertise_master AM where AD.adspaceId=SD.adspaceId and AD.advertiseId=AM.advertiseId and SD.adspaceIdMd='".md5(1)."' and AM.advertiseStatus = 'Y' and AM.startDate <= '".date('Y-m-d')."' and AM.endDate >= '".date('Y-m-d')."' and AD.networkId = 0 ";

// This query is only for direct NETWORK ADS but not for custom ads.......

//$sql_advertise="select * from advertise_details AD,advertise_master AM where AD.advertiseId=AM.advertiseId AND AD.networkId != 0 and AM.advertiseStatus = 'Y' ";

// $sites = mysql_query($sql_advertise);
// $arr = array();
// while($row_sites = mysql_fetch_array($sites))
// {
// 
// $query_site = "select * from ";
// echo "Net Id--->".$row_sites['networkId']."<br><br>";
// 
// $sql_advertise_inside="select ASM.adsiteId,NAC.categoryId from adsite_master ASM,network_ad_category NAC where NAC.networkId='$row_sites[networkId]' AND NAC.categoryId =  ASM.adcategoryId ";
// $any = mysql_query($sql_advertise_inside);
// while($res_site = mysql_fetch_array($any)){
// if(!in_array($res_site[adsiteId],$arr)){
// $arr[] = $res_site[adsiteId];
// }
// }
// }
// print_r($arr);


echo $sql_advertise;
	 $query_advertise=mysql_query($sql_advertise);
	 $rec=mysql_fetch_array(mysql_query($sql_advertise));
?>
<table class="center" cellspacing="7" cellpadding="0" border="0">
<tr>

<?php
		while($row_advertise=mysql_fetch_array($query_advertise))
		{
		// echo $row_advertise['adSize'];

if($row_advertise[adSize]=="184x360" && $row_advertise[thumbOrientation]=="vertical" )
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="468x60" && $row_advertise[thumbOrientation]=="horizontal" )
{
$val_tr=2;
}
elseif($row_advertise[adSize]=="234x60" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="728x90" && $row_advertise[thumbOrientation]=="horizontal")
{
$val_tr=5;
}
elseif($row_advertise[adSize]=="125x125" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="120x240" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="180x150" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="300x250" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=2;
}
elseif($row_advertise[adSize]=="336x280"  && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="250x250"  && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="120x600" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="160x600" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="" && $row_advertise[thumbOrientation]=="vertical")
{
$val_tr=1;
}
elseif($row_advertise[adSize]=="" && $row_advertise[thumbOrientation]=="horizontal")
{ 
$val_tr=$row_advertise[noOfTextAd];
}
else
{
$val_tr=2;
}

		$td++;
			  $tr++;
			  
				if($tr =="$val_tr")
				 {
				   $tr = 0;
				 }
if($row_advertise[fontType]!="")
{
$fontType=$row_advertise[fontType];
}
else
{
$fontType="Arial";
}

if($row_advertise[backgroundColor]!="")
{
$backgroundColor=$row_advertise[backgroundColor];
}
else
{
$backgroundColor="#E8E8E8";
}

//echo $backgroundColor;

if($row_advertise[headerColor]!="")
{
$headerColor=$row_advertise[headerColor];
}
else
{
$headerColor="#E8E8E8";
}
//echo $headerColor;

if($row_advertise[headerColor]!="")
{
$bodyColor=$row_advertise[bodyColor];
}
else
{
$bodyColor="#000000";
}
//echo $bodyColor;


?>
<td align="left">

		<table width="250" border="0" cellspacing="0" cellpadding="0" bgcolor="<?php echo $backgroundColor;?>">
              <tr>
                <td align="center">
					<a href="<?php echo $row_advertise[destinationUrl];?>" style="font-family: <?php echo $fontType;?>; color:<?php echo $headerColor;?>;">
					
					<?php
					echo $row_advertise[adTitle];
					?>
					</a>
                </td>
               </tr>

			 <tr>
                <td style="padding-left:20px;">
					<font color="<?php echo $bodyColor;?>" style="font-family: <?php echo $fontType;?>;">
					<?php
					echo $row_advertise[adTitle];
					?>
					</font>
                </td>
               </tr>

        </table>
		
		<?php
echo "</td>";
		if($td=="$val_tr")
							 {
								echo '</tr><tr>';
								$td=0;
							 }
}
		?>
		
	</tr>
</table>

